<!DOCTYPE html>
<html lang="en" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
  <link rel="stylesheet" href="/css/custom.form.css">
</head>
<body>
<div class="panel panel-default operation" hidden>
    <div class="panel-heading title"></div>
    <div class="layui-card-body">
        <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
            <input name="id" hidden/>
            <div class="layui-form-item">
                <label class="layui-form-label">客户名称</label>
                <div class="layui-input-block">
                    <input type="khname" name="khname" placeholder="请输入客户名称" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系人</label>
                <div class="layui-input-block">
                    <input type="lxr" name="lxr" placeholder="请输入联系人" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="lxdh" name="lxdh" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">其他电话</label>
                <div class="layui-input-block">
                    <input type="ssxs" name="qtdh" placeholder="多个电话时，用；分隔" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">客户来源</label>
                <div class="layui-input-block">
                    <select id="khlySCF" name="khly">
                        <option value="">请选择客户来源</option>
                    </select>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">意向度</label>
                <div class="layui-input-block">
                    <select id="kujbSCF" name="khjb">
                        <option value="">请选择意向度</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="bz" name="bz" placeholder="请输入备注" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
                    <button class="layui-btn layui-btn-primary" id="btn_cancel">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="panel panel-default " id="operationlrgh" hidden>
    <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
        <div class="layui-form-item">
            <label class="layui-form-label">公海</label>
            <div class="layui-input-block">
                <select id="lrghSCF" name="khly">
                    <option value="">请选择公海</option>
                </select>
            </div>
        </div>
    </form>
</div>

<div class="table_div">
  <div id="searchParam"  shiro:hasPermission="tWdkh:list">
    <div class="layui-form-item">
      <div class="layui-input-inline">
        <input type="text" id="company" class="layui-input"  autocomplete="off" placeholder="请输入公司名称">
      </div>
        <div class="layui-input-inline">
            <input type="text" id="lxr" class="layui-input"  autocomplete="off" placeholder="请输入联系人">
        </div>
        <div class="layui-input-inline">
            <input type="text" id="lxdh" class="layui-input"  autocomplete="off" placeholder="请输入联系电话">
        </div>
        <div class="layui-input-inline layui-form" id="khjbSCid">
            <select id="kujbSC">
                <option value="">请选择意向度</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form" id="deptSCid" >
            <select id="deptSC">
                <option value="">请选择部门</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form" id="ssxsSCid" >
            <select id="ssxsSC">
                <option value="">请选择所属销售</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form" id="khlySCid" >
            <select id="khlySC">
                <option value="">请选择客户来源</option>
            </select>
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range0" placeholder="请选择下次跟进时间">
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range1" placeholder="请选择入库时间">
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range2" placeholder="请选择流公海时间">
        </div>
        <div class="layui-input-inline layui-form">
            <input type="text" name="date" class="layui-input" id="test-range3" placeholder="请选择最后跟进时间">
        </div>
      <div class="layui-input-inline ">
        <button class="layui-btn" onclick="search()"  id="search">查询</button>
          <button type="button" class="layui-btn" id="uploadFile-button" style="display:none">
              <i class="layui-icon">&#xe67c;</i>上传文件
          </button>

      </div>
    </div>
  </div>
  <table class="layui-table" id="showTable" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolbar">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add"  shiro:hasPermission="tWdkh:add">添加客户</button>
    <button class="layui-btn layui-btn-sm" lay-event="zy" shiro:hasPermission="tWdkh:zy">转移</button>
    <button class="layui-btn layui-btn-sm" lay-event="lrgh" shiro:hasPermission="tWdkh:lrgh">扔入公海</button>
    <button class="layui-btn layui-btn-sm" lay-event="batchDeleted" shiro:hasPermission="tWdkh:delete">删除</button>
      <button  class="layui-btn layui-btn-sm" lay-event="khcc" shiro:hasPermission="tWdkh:khcc">客户查重</button>
      <button style="float:right" class="layui-btn layui-btn-sm" lay-event="pldr" shiro:hasPermission="tWdkh:pldr"><i class="layui-icon">&#xe67c;</i>批量导入</button>

      <button style="float:right" class="layui-btn layui-btn-sm" lay-event="xzmb" shiro:hasPermission="tWdkh:xzmb">下载模板</button>
  </div>
</script>
<script type="text/html" id="tool">
    {{#  if(d.isbd == "0"){ }}
  <a class="layui-btn layui-btn-xs" lay-event="hujiao"shiro:hasPermission="twdkh:wh" >呼叫</a>
    {{#  } }}
    {{#  if(d.isbd == "1" ){ }}
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="hujiao" shiro:hasPermission="twdkh:wh">呼叫</a>
    {{#  } }}
  <a class="layui-btn layui-btn-xs" lay-event="xjl" >写记录</a>
  <a class="layui-btn layui-btn-xs" lay-event="info" >查看</a>
</script>
<div id="zhuanyidata" hidden>
    <div class="panel panel-default operation2" >
        <div class="panel-heading title"></div>
        <div class="layui-card-body">
            <form class="layui-form " action="" lay-filter="info" style="width: 700px;margin-top: 10px">
                <input name="id" hidden/>
                <div class="layui-form-item">
                    <label class="layui-form-label">变更负责人</label>
                    <div class="layui-input-block">
                        <select id="username">
                            <option value="">请选择负责人</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <div class="layui-input-block">
                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="submit2" id="zysubmit">确定</button>
                        <button  class="layui-btn layui-btn-primary" id="btn_cancelzhuanyi">返回</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="table_divkhcc" hidden >
    <div id=""  >
        <div class="layui-form-item">
            <div class="layui-input-inline layui-form" >
                <select id="reType">
                    <option value="1">公司名称</option>
                    <option value="2">联系方式</option>
                </select>
            </div>
            <div class="layui-input-inline">
                <input type="text" id="repeat" class="layui-input"  autocomplete="off" placeholder="请输入">
            </div>

            <div class="layui-input-inline ">
                <button class="layui-btn" onclick="searchRepeat()"  id="searchRepeat">查重</button>
            </div>
        </div>
    </div>
    <table class="layui-table" id="showTableKhcc" lay-filter="showTable" ></table>
</div>
<div class="table_divqtkh" hidden >
    <table class="layui-table" id="showTableqtkh" lay-filter="showTable" ></table>
</div>
<script type="text/html" id="toolKhcc">
    {{#  if(d.ssxs == "" || d.ssxs == null || d.ssxs == undefined){ }}
    <a class="layui-btn layui-btn-xs" lay-event="lingqu" >领取</a>
    {{#  } }}
</script>
<script type="text/html" id="toolqtdh">
    <a class="layui-btn layui-btn-xs" lay-event="hujiaoqtdh" shiro:hasPermission="twdkh:wh">呼叫</a>
</script>
</body>
</html>
<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script src="/js/jquery.js"></script>
<script src="/js/common.js"></script>
<script src="/js/jquery.fileDownload.js"></script>
<script>
  //获取token
  var token = CoreUtil.getData("access_token");
  //地址栏转义token中的#号
  var tokenQuery = token.replace("#", "%23");
  var tableIns1;
  var tableIns2;
  var tableInskhcc;
  var table = layui.table;
  var form = layui.form;
  var layer = layui.layer;
  var laydate = layui.laydate;
  var upload = layui.upload;
  var idsData = layui.ids;
  var currPage = 1;//首先默认值为1，防止出错
  info();
  var isycVo;
  var dataQtdh;
  var wdkhIdVo;
  layui.use(['table', 'layer', 'laydate','upload'], function () {
      laydate.render({
          elem: '#test-range0' ,//指定元素
          range: true,
      });
      laydate.render({
          elem: '#test-range1' ,//指定元素
          range: true,
      });
      laydate.render({
          elem: '#test-range2' ,//指定元素
          range: true,
      });
      laydate.render({
          elem: '#test-range3' ,//指定元素
          range: true,
      });
      //执行实例
      var uploadInst = upload.render({
          elem: '#uploadFile-button' //绑定元素
          ,url: '/wd/tWdkh/upload?authorization='+tokenQuery //上传接口
          ,accept: 'file' //允许上传的文件类型
          ,acceptMime: ".zip,.rar,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx"
          ,exts: "zip|rar|pdf|doc|docx|xls|xlsx|ppt|pptx"
          ,before: function(obj) {
              layer.msg("正在导入文件中", {shade:0.4, icon:16, time:1000});
          }
          ,done: function(res){
             var data =  res.data;
              if (res.code == 0) {
                  if (!!data){
                      alert(data+" 异常数据未上传成功！")
                  }
                  layer.msg("上传成功", {shade:0.4, icon:16, time:1000});
                  search();
              }else{
                  layer.msg(res.msg, {shade:0.4, icon:16, time:1000});
              }
          }
          ,error: function(res){
              //请求异常回调
              layer.msg("请求异常回调", {shade:0.4, icon:16, time:1000});
          }
      });
      var tableInsKhcc = function () {
          // $(".table_div").hide();
          // $(".table_divkhcc").show();
          layer.open({
              type: 1,
              skin: 'layui-layer-molv',
              title: "客户查重",
              area: ['70%', '80%'],
              shade: 0,
              shadeClose: false,
              content: jQuery(".table_divkhcc"),
              end:function (res) {$(".table_divkhcc").css("display",'none');},
              btn: ['关闭'],
              yes: function (index) {
                  layer.close(index);
              }
          });

          //加载table
          tableInskhcc = table.render({
              elem: '#showTableKhcc'
              , contentType: 'application/json'
              , headers: {"authorization": token}
              , page: true //开启分页
              , url: '/tWdkh/khcc/listByPage' //数据接口
              , method: 'POST'
              , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                  return {
                      "code": res.code, //解析接口状态
                      "msg": res.msg, //解析提示文本
                      "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                      "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
                  }
              }
              , cols: [
                  [
                      {type: 'checkbox', fixed: 'left'},
                      {field: 'khname', title: '客户名称',width: 220 , sort: true,align: 'center' , templet: function (item) {
                              return item.khname;
                          }},
                      {field: 'rktime', title: '创建时间',width: 220 , sort: true,align: 'center'},
                      {field: 'ssxs', title: '负责人',width: 120 , sort: true,align: 'center' , templet: function (item) {
                          if(!!item.ssxs){
                              return "**";
                          }else {
                              return "";
                          }
                          }},
                      {field: 'zhgjtime', title: '最后跟进时间',width: 220 , sort: true,align: 'center'},
                      {width: 120, toolbar: "#toolKhcc", title: '操作'}
                  ]
              ]
          });
      }

    //表头工具
    table.on('toolbar(showTable)', function(obj){
      switch(obj.event){
        case 'batchDeleted':
          var checkStatus = table.checkStatus(obj.config.id);
          var data = checkStatus.data;
          if(data.length==0){
            layer.msg("请选择要批量删除的列");
          }else {
            var ids = [];
            $(data).each(function (index,item) {
              ids.push(item.id);
            });
            tipDialog(ids);
          }
          break;
        case 'add':
            layer.open({
                type: 2,
                title: '<i class=iconfont>&#xe7e0;</i> 新增',
                area: ['70%', '80%'],
                content: ["/index/tWdkh/add", 'yes'],
                skin: 'layui-layer-molv',
                btn: ['立即提交', '关闭'],
                btnAlign: 'c',
                shadeClose: true,
                shade: 0.8,
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                    submit.click();// 触发提交监听
                    return false;
                }
            });
          break;
        case 'zy':
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(data.length==0){
                layer.msg("请选择要批量转移的列");
            }else {
                var ids = [];
                $(data).each(function (index,item) {
                    ids.push(item.id);
                });
                zhuanyilog(ids,"转移");
            }
            break;
          case 'lrgh':
              var checkStatus = table.checkStatus(obj.config.id);
              var data = checkStatus.data;
              if(data.length==0){
                  layer.msg("请选择要批量扔入公海的列");
              }else {
                  var ids = [];
                  $(data).each(function (index,item) {
                      ids.push(item.id);
                  });
                  lrghlog(ids);
              }
              break;
          case 'pldr' :
              $("#uploadFile-button").click();
              break;
          case 'khcc' :
              tableInsKhcc();
              break;
          case 'xzmb' :
              $.fileDownload("/sysGenerator/model?authorization=" + tokenQuery,{httpMethod: 'get'})
              break;
      };
    });

        //列操作
    table.on('tool(showTable)',function (obj) {
        var data = obj.data;
        switch (obj.event) {
        case 'del':
          var ids=[];
          ids.push(data.id);
          tipDialog(ids);
          break;
          case 'lingqu': //领取
              lingqulog(data);
              break;
          case 'fenpei'://分配
              $(".table_divkhcc").hide();
              $(".operation2").show();
              $(".title").html("分配");

              var ids = [];
              $(data).each(function (index,item) {
                  ids.push(item.id);
              });
              zhuanyilog(ids);
              break;

        }
    });
    //列操作
    table.on('toolKhcc(showTable)',function (obj) {
      var data = obj.data;
      switch (obj.event) {
          case 'lingqu': //领取
              lingqulog(data);
              break;
          case 'fenpei'://分配
              var ids = [];
              $(data).each(function (index,item) {
                  ids.push(item.id);
              });
              zhuanyilog(ids);
              break;
      }
    });
    table.on('toolqtdh(showTableqtkh)',function (obj) {
          var data = obj.data;
          switch (obj.event) {

          }
      });

    table.on('tool(showTable)', function (obj) {
      let event = obj.event;
      let data = obj.data;
      switch (obj.event) {
          case 'lingqu': //领取
              lingqulog(data);
              break;
          case 'fenpei'://分配
              var ids = [];
              $(data).each(function (index,item) {
                  ids.push(item.id);
              });
              zhuanyilog(ids,"分配");
              break;
          case 'hujiao': //呼叫
              data.hjType = '0';//呼叫主要号码
              hujiao(data);
              break;
          case 'hujiaoqtdh': //呼叫
              data.hjType = '1';//呼叫其他号码
              data.lxdh = data.qtdh;
              hujiao(data);
              break;
          case 'xjl':   //写记录
              layer.open({
                  type: 2,
                  title: '<i class=iconfont>&#xe7c7;</i> 写记录',
                  area: ['80%', '70%'],
                  content: ['/index/tGjjl/add/'+data.id, 'yes'],
                  skin: 'layui-layer-molv',
                  btn: ['立即提交', '关闭'],
                  btnAlign: 'c',
                  shadeClose: true,
                  shade: 0.8,
                  yes: function(index, layero){
                      var submit = layero.find('iframe').contents().find("#submit");// #subBtn为页面层提交按钮ID
                      submit.click();// 触发提交监听
                      layer.close(index);
                      // search();
                      return false;
                  }
              });
              break;
          case 'info':   //查看
              window.open("/index/tWdkh/wdkhedit/"+data.id);
              break;
      }
    });
    //双击
    table.on('rowDouble(showTable)',function(obj){
      let event = obj.event;
      let data = obj.data;
      //详情
      // if (event === "khname") {
          window.open("/index/tWdkh/wdkhedit/"+data.id);
      // }
    });
    var hujiao = function (data) {

        debugger
        layer.msg("云点呼正在检测被叫黑名单，请稍等！", {time: 2000}, function () {
            CoreUtil.sendPost("/tWdkh/outbound", data, function (res) {
                layer.msg(res.msg)
                search();
            });
        });
    }

    //删除
    var tipDialog=function (ids) {
      layer.open({
        content: "确定要删除么?",
        yes: function(index, layero){
          layer.close(index); //如果设定了yes回调，需进行手工关闭
          CoreUtil.sendDelete("/tWdkh/delete",ids,function (res) {
            layer.msg(res.msg, {time:1000},function () {
              search();
            });
          });
        }
      });
    };
    //仍入公海
      var lrghlog=function (ids) {
          layer.open({
              type: 1,
              skin: 'layui-layer-molv',
              title: "仍入公海",
              area: ['70%', '80%'],
              shade: 0,
              shadeClose: true,
              content: jQuery("#operationlrgh"),
              btn: ['立即提交','关闭'],
              end:function (res) {$("#operationlrgh").css("display",'none');},
              yes: function(index, layero){
                  var ghmc = $("#lrghSCF").val();
                  var pamara = {
                      ids: ids,
                      ghmc: ghmc
                  }
                  CoreUtil.sendPost("/tWdkh/rlgh",pamara,function (res) {
                      layer.msg(res.msg, {time:1000},function () {
                          search();
                          layer.close(index); //如果设定了yes回调，需进行手工关闭
                      });
                  });
              }
          });
      };
    var zhuanyilog=function (ids,title){
        idsData = ids;
        layer.open({
            type: 1,
            skin: 'layui-layer-molv',
            title: title,
            area: ['70%', '80%'],
            shade: 0,
            shadeClose: false,
            content: jQuery("#zhuanyidata"),
            btn: ['立即提交','关闭'],
            end:function (res) {$("#zhuanyidata").css("display",'none');},
            yes: function (index) {
                var username = $.trim($("#username").val());//Id
                if (username != undefined && username != ''){
                    var params = {
                        username: username,
                        ids: ids
                    }
                    CoreUtil.sendPost("/tWdkh/zhuanyi", params, function (res) {
                        var code = res.code;
                        //同步数据失败
                        if (code!=0){
                            layer.msg(res.msg,{time:1000});
                        }
                        search();
                        searchRepeat();
                    });
                }
                layer.close(index);
            }
        });
    }
    var lingqulog = function (data) {
        var ids = [];
        $(data).each(function (index,item) {
            ids.push(data.id);
        });
        CoreUtil.sendPost("/tGhkh/lingqu", ids, function (res) {
            var code = res.code;
            //同步数据失败
            if (code!=0){
                layer.msg(res.msg,);
            }
            search();
            searchRepeat();
        });
    }

    //返回
    $("#btn_cancel").click(function() {
      $(".table_div").show();
      $(".operation").hide();
      return false;
    });

    form.on('submit2(submit)', function(data){
          if(data.field===undefined || data.field===null || data.field===""){
              var username = data.field;
              var params = {
                  username: username,
                  ids: idsData
              }
              CoreUtil.sendPut("/tWdkh/zhuanyi", params, function (res) {
                  var code = res.code;
                  //同步数据失败
                  if (code!=0){
                      layer.msg(res.msg,);
                  }
                  search();
              });
          }
          return false;
      });
    //监听保存
    form.on('submit(submit)', function(data){
      if(data.field.id===undefined || data.field.id===null || data.field.id===""){
        CoreUtil.sendPost("/tWdkh/add",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }else {
        CoreUtil.sendPut("/tWdkh/update",data.field,function (res) {
          $(".table_div").show();
          $(".operation").hide();
          search();
        });
      }
      return false;
    });
  });

  function info() {
      CoreUtil.sendGet("/tWdkh/infoData/", null, function (res) {
          var code = res.code;
          var data = res.data;
          //username、 khlySC 请选择客户来源、请选择意向度、请选择所属销售; deptSC 所属部门
          if (code == 0) {
              //username
              var username = $("#username");
              $.each(data.username, function (index, item) {
                  if (!!item) {
                      username.append("<option value=" + item + ">" + item + "</option>");
                  }
              });
              //客户来源
              var khlySC = $("#khlySC");
              var khlySCF = $("#khlySCF");
              $.each(data.khly, function (index, item) {
                  khlySC.append("<option value=" + item + ">" + item + "</option>");
                  khlySCF.append("<option value=" + item + ">" + item + "</option>");
              });
              //意向度
              var kujbSC = $("#kujbSC");
              var kujbSCF = $("#kujbSCF");
              var kujbSCFeidt = $("#kujbSCFeidt");
              $.each(data.hkjb, function (index, item) {
                  if (!!item) {
                      kujbSC.append("<option value=" + item.id + ">" + item.value + "</option>");
                      kujbSCF.append("<option value=" + item.id + ">" + item.value + "</option>");
                      kujbSCFeidt.append("<option value=" + item.id + ">" + item.value + "</option>");
                  }
              });
              //所属销售
              var ssxsSC = $("#ssxsSC");
              $.each(data.ssxs, function (index, item) {
                  if (!!item) {
                      ssxsSC.append("<option value=" + item + ">" + item + "</option>");
                  }
              });
              //所属部门
              var deptSC = $("#deptSC");
              $.each(data.dept, function (index, item) {
                  if (!!item) {
                      deptSC.append("<option value=" + item.id + ">" + item.name + "</option>");
                  }
              });
              //公海名称
              var lrghSCF = $("#lrghSCF");
              $.each(data.gh, function (index, item) {
                  if (!!item) {
                      lrghSCF.append("<option value=" + item.id + ">" + item.ghmc + "</option>");
                  }
              });
              isycVo = data.isyc;
              form.render("select");
          }
          userInfo = CoreUtil.getData("userInfo");
          userRoles = CoreUtil.getData("userRoles");
          userDepts = CoreUtil.getData("userDepts");
          sysRolesList = CoreUtil.getData("sysRolesList");
          userSysUsers = CoreUtil.getData("userSysUsers");
          hwtj = CoreUtil.getData("hwtj");
          if (userInfo.sysRoleName == '员工') {
              var ssxsSCid = document.getElementById("ssxsSCid");
              ssxsSCid.style.display = "none";
              var deptSCid = document.getElementById("deptSCid");
              deptSCid.style.display = "none";

          }
          if (currPage == 1) {
              //加载表格
              tableIns();
          }
      });


      };
  function tableIns() {
      //加载table
      tableIns1 = table.render({
          elem: '#showTable'
          , contentType: 'application/json'
          , headers: {"authorization": token}
          , page: true //开启分页
          , url: '/tWdkh/listByPage' //数据接口
          , method: 'POST'
          , limits: ['10', '20', '50','100', '300', '500', '1000']//分页每页显示数据条数（页面选择
          , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
              return {
                  "code": res.code, //解析接口状态
                  "msg": res.msg, //解析提示文本
                  "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                  "data": CoreUtil.isEmpty(res.data) ? null : res.data.records //解析数据列表
              }
          }
          ,done: function(res, curr, count){
              //如果是异步请求数据方式，res即为你接口返回的信息。
              /**
               *如果是直接赋值的方式，
               *res即为：{data: [], count: 99}
               *data为当前页数据、count为数据总长度
               */
              console.log(res);
              currPage = curr;//将当前页码赋值给全局变量currPage
              //得到当前页码
              console.log(curr);

              //得到数据总量
              console.log(count);
          }
          , cols: [
              [
                  //:客户名称、联系人、联系电话、所属销售、意向度、去电次数、跟进记录、最后跟进时间、下次联系时间、入库时间、客户来源、备注、流公海时间
                  {type: 'checkbox', fixed: 'left'},
                  {field: 'khname', title: '客户名称',event: 'khname',width: 240 ,
                      style: 'color: #003CFFFF; cursor:pointer',sort: true,align: 'center',fixed: "left"},
                  {field: 'lxr', title: '联系人', width: 100 ,sort: true,align: 'center',fixed: "left"},
                  {field: 'lxdh', title: '联系电话', width: 140 ,templet: function (item) {
                          if (item.lxdh.length == 11 && isycVo == 1) { //是否隐藏
                              return item.lxdh.replace(item.lxdh.substring(3, 7), "****");
                          } else if (item.lxdh.length > 11 && isycVo == 1) { //是否隐藏
                              return item.lxdh.replace(item.lxdh.substring(3, 9), "****");
                          } else {
                              return item.lxdh;
                          }
                      }, align: 'center',fixed: "left"},
                  {field: 'khjb', title: '意向度', width: 90 ,sort: true,align: 'center',fixed: "left"},
                  {field: 'ssxs', title: '所属销售', width: 120 ,sort: true,align: 'center'},
                  {field: 'qdcs', title: '去电次数', width: 100 ,sort: true,align: 'center'},
                  // {field: 'gjjl', title: '跟进记录', width: 110 , event: 'viewReport',style: 'font-size: 12px; color: #666; cursor:pointer', sort: true,align: 'center'},
                  {field: 'zhgjtime', title: '最后跟进时间',width: 200 , sort: true,align: 'center'},
                  {field: 'xclxtime', title: '下次联系时间',width: 200 , sort: true,align: 'center'},
                  {field: 'rktime', title: '入库时间',width: 200 , sort: true,align: 'center'},
                  {field: 'khly', title: '客户来源',width: 120 ,  sort: true,align: 'center'},
                  {field: 'bz', title: '备注', width: 100 , sort: true,align: 'center'},
                  {field: 'lrghtime', title: '流公海时间',width: 200 , sort: true,align: 'center'},
                  {field: 'qtdh', title: '其他电话',width: 220 , event: 'qtdh',templet: function (item) {
                          if ( isycVo == 1) { //是否隐藏
                              return "****";
                          } else {
                              return item.qtdh;
                          }
                      }, style: 'font-size: 12px; color: #666; cursor:pointer', sort: true,align: 'center'},
                  {field: 'khdz', title: '客户地址', width: 220 , sort: true,align: 'center'},
                  {field: 'khhy', title: '客户行业', width: 220 , sort: true,align: 'center'},
                  {width: 220, toolbar: "#tool", title: '操作',fixed: "right"}
              ]
          ]
          , toolbar: '#toolbar'
      });
  }

  //执行查询
  function search() {
      var split0 = $('#test-range0').val().replace(/ - /g, ' 至 ').split(' 至 ');
      var split1 = $('#test-range1').val().replace(/ - /g, ' 至 ').split(' 至 ');
      var split2 = $('#test-range2').val().replace(/ - /g, ' 至 ').split(' 至 ');
      var split3 = $('#test-range3').val().replace(/ - /g, ' 至 ').split(' 至 ');
      //这里以搜索为例
      tableIns1.reload({
          where: { //设定异步数据接口的额外参数，任意设
              khname: $("#company").val(),
              lxr: $("#lxr").val(),
              lxdh: $("#lxdh").val(),
              khjb: $("#kujbSC").val(),
              ssxs: $("#ssxsSC").val(),
              khly: $("#khlySC").val(),
              dept: $("#deptSC").val(),
              xclxStartDate: split0[0],
              xclxEndDate: split0[1],
              rkStartDate: split1[0],
              rkEndDate: split1[1],
              lrghStartDate: split2[0],
              lrghEndDate: split2[1],
              zhgjStartDate: split3[0],
              zhgjEndDate: split3[1],
          }
          , page: {
              curr: currPage //首先默认值为1，防止出错 //重新从第 1 页开始
          }
      });
  }
  /**
   *  客户查重搜索
   */
  function searchRepeat() {
      var reType = $("#reType").val();
      //1:公司名称 2:联系方式
      var params;
      if (reType == "1") {
          params = {
              khname: $("#repeat").val(),
              lxdh: ""
          }
      } else if (reType == "2") {
          params = {
              lxdh: $("#repeat").val(),
              khname: ""
          }
      }
      //这里以搜索为例
      tableInskhcc.reload({
          where: params
          , page: {
              curr: currPage //重新从第 1 页开始
          }
      });
  };
</script>
